import request from '@/utils/request'

// 获取通知列表
export function getNotificationList() {
  return request({
    url: '/notifications',
    method: 'get'
  })
}

// 根据 ID 获取通知详情
export function getNotificationDetail(id) {
  return request({
    url: `/notifications/${id}`,
    method: 'get'
  })
}

// 新增通知
export function addNotification(data) {
  return request({
    url: '/notifications',
    method: 'post',
    data
  }).then(response => {
    if (response.data.code !== 1) {
      return Promise.reject(new Error(response.data.msg || '新增通知失败'))
    }
    return response
  })
}

// 更新通知类型
export function updateNotificationStatus(id, notificationType) {
  return request({
    url: `/notifications/${id}/status`,
    method: 'put',
    params: {
      notificationType
    }
  })
}

// 删除通知
export function deleteNotification(id) {
  return request({
    url: `/notifications/${id}`,
    method: 'delete'
  })
}
